﻿@model HZYProject.Domain.Student
@{ var className = ViewBag.ClassNames as List<HZYProject.Domain.Class>; }
<div class="layer-edit">
    <form id="formEdit" class="layui-form" action="" onsubmit="return false">
        <input type="hidden" name="StudentID" value="@Model.StudentID" />
        <div class="layui-form-item">
            <label class="layui-form-label">学生姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="RealName" value="@Model.RealName" required lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属班级</label>
            <div class="layui-input-inline">
                <select id="ClassID" name="ClassID" multiple="multiple" lay-search="" lay-verify="required">
                    <option value="">--全部--</option>
                    @{
                        foreach (var item in className)
                        {
                            <option value="@item.ClassID">@item.Name</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="text" name="Mphone" value="@Model.Mphone" required lay-verify="required|phone" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="Email" value="@Model.Email" required lay-verify="email" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                @{
                    if (Model.Sex == "男")
                    {
                        <input type="radio" name="Sex" value="男" title="男" checked>
                        <input type="radio" name="Sex" value="女" title="女">
                    }
                    else
                    {
                        <input type="radio" name="Sex" value="男" title="男">
                        <input type="radio" name="Sex" value="女" title="女" checked>
                    }
                }
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                @{
                    if (Convert.ToInt32(Model.Status) == 1)
                    {
                        <input type="radio" name="Status" value="1" title="正常" checked>
                        <input type="radio" name="Status" value="2" title="锁定">
                        <input type="radio" name="Status" value="3" title="冻结">
                    }
                    else if (Convert.ToInt32(Model.Status) == 2)
                    {
                        <input type="radio" name="Status" value="1" title="正常">
                        <input type="radio" name="Status" value="2" title="锁定" checked>
                        <input type="radio" name="Status" value="3" title="冻结">
                    }
                    else if (Convert.ToInt32(Model.Status) == 3)
                    {
                        <input type="radio" name="Status" value="1" title="正常">
                        <input type="radio" name="Status" value="2" title="锁定">
                        <input type="radio" name="Status" value="3" title="冻结" checked>
                    }
                }
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="formDemo">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</div>
@section script{
    <script>
        layui.use(['form', 'jquery'], function () {
            var form = layui.form;
            let $ = layui.jquery;

            form.on('submit(formDemo)', function (data) {
                var str = $("#formEdit").serialize();
                $.post("/Student/edit", str, function (res) {
                    if (res.success) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                    else
                        layer.msg("修改失败：" + res.msg, {
                            icon: 2,
                            time: 1000
                        });
                }, "json");
                return false;
            });
        });
    </script>
}